

import pylab, sys

f = open(sys.argv[1])

x="""
for line in f.readlines():
	nt, nb = line.split(",")
	if int(nt)%2 == 0:
		wt.append(nt)
		wb.append(nb)
	else:
		bt.append(nt)
		bb.append(nb)
"""

current = [0,1]
acc = [[],[]]
t = []
b = []
while True:
	line = f.readline()
	if not line: break
	nt, nb = line.split(",")
	nt = int(nt)
	nb = int(nb)
	col = nt%2
	if nt == current[col]:
		acc[col].append(nb)
	else:
		print current, acc
		try:
			t.append(current[col])
			b.append(sum(acc[col])/len(acc[col]))
		except:
			pass

		acc[col] = [nb]
		current[col] = nt



print sum(b)/float(len(b))

pylab.xlabel("Turn number")
pylab.ylabel("Branching Factor")


pylab.plot(t,b)
pylab.savefig(sys.argv[1]+".eps")
pylab.show()

